﻿//-----------------------------------------------------------------------
// <copyright file="MessageBoxControlPage.cs" company="Noboru Project">
//      Copyright (c) Noboru Project. All rights reserved.
//
//      This source code is subject to terms and conditions of the New BSD License (BSD).
//      A copy of the license can be found in the License.html file at the root of this 
//      distribution. If you can not locate the New BSD License (BSD), please send an 
//      email to noboru_adm@live.com.
//      By using this source code in any fashion, you are agreeing to be bound by
//      the terms of the New BSD License (BSD) for Noboru.
//
//      You must not remove this notice, or any other, from this software.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Noboru.Windows.Controls;

namespace Noboru.Demo
{
    public partial class MessageBoxControlPage : UserControl
    {
        public MessageBoxControlPage()
        {
            this.InitializeComponent();
        }

        private void ShowMessageButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxControl messageBoxControl = new MessageBoxControl();
            messageBoxControl.Closed += new EventHandler(this.messageBoxControl_Closed);

            messageBoxControl.Title = this.txtTitle.Text;
            messageBoxControl.Message = this.txtMessage.Text;

            if (this.RadioNone.IsChecked.Value)
            {
                messageBoxControl.MessageBoxIcon = MessageBoxIcon.None;
            }
            else if (this.RadioHand.IsChecked.Value)
            {
                messageBoxControl.MessageBoxIcon = MessageBoxIcon.Hand;
            }
            else if (this.RadioQuestion.IsChecked.Value)
            {
                messageBoxControl.MessageBoxIcon = MessageBoxIcon.Question;
            }
            else if (this.RadioExclamation.IsChecked.Value)
            {
                messageBoxControl.MessageBoxIcon = MessageBoxIcon.Exclamation;
            }
            else if (this.RadioAsterisk.IsChecked.Value)
            {
                messageBoxControl.MessageBoxIcon = MessageBoxIcon.Asterisk;
            }
            else if (this.RadioStop.IsChecked.Value)
            {
                messageBoxControl.MessageBoxIcon = MessageBoxIcon.Stop;
            }
            else if (this.RadioError.IsChecked.Value)
            {
                messageBoxControl.MessageBoxIcon = MessageBoxIcon.Error;
            }
            else if (this.RadioWarning.IsChecked.Value)
            {
                messageBoxControl.MessageBoxIcon = MessageBoxIcon.Warning;
            }
            else if (this.RadioInformation.IsChecked.Value)
            {
                messageBoxControl.MessageBoxIcon = MessageBoxIcon.Information;
            }

            if (this.RadioOk.IsChecked.Value)
            {
                messageBoxControl.MessageBoxButtons = MessageBoxButtons.OK;
            }
            else if (this.RadioOkCancel.IsChecked.Value)
            {
                messageBoxControl.MessageBoxButtons = MessageBoxButtons.OKCancel;
            }
            else if (this.RadioAbortRetryIgnore.IsChecked.Value)
            {
                messageBoxControl.MessageBoxButtons = MessageBoxButtons.AbortRetryIgnore;
            }
            else if (this.RadioYesNoCancel.IsChecked.Value)
            {
                messageBoxControl.MessageBoxButtons = MessageBoxButtons.YesNoCancel;
            }
            else if (this.RadioYesNo.IsChecked.Value)
            {
                messageBoxControl.MessageBoxButtons = MessageBoxButtons.YesNo;
            }
            else if (this.RadioRetryCancel.IsChecked.Value)
            {
                messageBoxControl.MessageBoxButtons = MessageBoxButtons.RetryCancel;
            }

            if (RadioButton1.IsChecked.Value)
            {
                messageBoxControl.MessageBoxDefaultButton = MessageBoxDefaultButton.Button1;
            }
            else if (RadioButton2.IsChecked.Value)
            {
                messageBoxControl.MessageBoxDefaultButton = MessageBoxDefaultButton.Button2;
            }
            else if (RadioButton3.IsChecked.Value)
            {
                messageBoxControl.MessageBoxDefaultButton = MessageBoxDefaultButton.Button3;
            }

            messageBoxControl.ShowModal();
        }

        void messageBoxControl_Closed(object sender, EventArgs e)
        {
            string result = string.Empty;
            StringBuilder message = new StringBuilder();

            switch (((MessageBoxControl)sender).DialogResult)
            {
                case DialogResult.Abort:
                    result = "Abort";
                    break;

                case DialogResult.Cancel:
                    result = "Cancel";
                    break;

                case DialogResult.Ignore:
                    result = "Ignore";
                    break;

                case DialogResult.No:
                    result = "No";
                    break;

                case DialogResult.None:
                    result = "None";
                    break;

                case DialogResult.OK:
                    result = "OK";
                    break;

                case DialogResult.Retry:
                    result = "Retry";
                    break;

                case DialogResult.Yes:
                    result = "Yes";
                    break;
            }

            message.AppendFormat("DialogResult = {0}", result);

            this.txtDialogResult.Text = message.ToString();
        }
    }
}
